/**
 * 
 */
package belote.webapp.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * @author Gwenn
 * 
 */
public class EncodingFilter implements Filter {

	private static final String ENCODING = "UTF-8";

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void init(FilterConfig pFilterConfig) throws ServletException {
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void doFilter(ServletRequest pRequest, ServletResponse pResponse, FilterChain pChain) throws IOException, ServletException {

		if (pRequest.getCharacterEncoding() == null) {
			pRequest.setCharacterEncoding(ENCODING);
		}

		pResponse.setCharacterEncoding(ENCODING);

		pChain.doFilter(pRequest, pResponse);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void destroy() {
	}

}
